package com.agger.harmonyosthemeseditor.userinterface;

import com.agger.harmonyosthemeseditor.ResourceTable;
import com.agger.harmonyosthemeseditor.ThemesEditorAbility;
import com.agger.harmonyosthemeseditor.abilities.slices.MainSceneSlice;
import com.agger.harmonyosthemeseditor.data.RequestParam_i18n;
import com.agger.harmonyosthemeseditor.intelligent.DatabaseManager;
import com.huawei.agconnect.remoteconfig.AGConnectConfig;
import com.huawei.agconnect.remoteconfig.ConfigValues;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.*;
import ohos.agp.components.element.VectorElement;
import ohos.agp.utils.Point;
import ohos.agp.window.service.Display;
import ohos.agp.window.service.DisplayAttributes;
import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;
import ohos.eventhandler.InnerEvent;
import ohos.global.configuration.DeviceCapability;
import ohos.global.resource.ResourceManager;
import ohos.os.ProcessManager;
import ohos.system.version.SystemVersion;
import ohos.utils.net.Uri;
import ohos.utils.zson.ZSONObject;

import java.util.ArrayList;
import java.util.List;

public class PageSwiper extends PageSliderProvider {

    private PageSlider ImageSwiper_Industry;
    public EventRunner ImageSwiperAutoPlayEventRunner;
    private ImageSwiperAutoPlayEventHandler imageSwiperAutoPlayEventHandler;
    public static MainSceneSlice mainSceneSlice;
    private Text iBoard_Title,iBoard_Content,iBoard_Date;
    public Component iBoard_Base,iBoard_Content_Layout,iBoard_Date_Layout;
    private boolean Complete = false;
    private Object[] objects;

    private class ImageSwiperAutoPlayEventHandler extends EventHandler
    {
        private ImageSwiperAutoPlayEventHandler(EventRunner runner) {
            super(runner);
        }
        // 重写实现processEvent方法
        @Override
        public void processEvent(InnerEvent event)
        {
            //new GeneralToast(mContext).setText("!!!").show();
            super.processEvent(event);
            if(event.eventId == 0)
            {
                if(ThemesEditorAbility.isMainSceneSlice)
                {
                    int target = ImageSwiper_Industry.getCurrentPage();
                    if(target >= (getSwiperImages_Industry().size()-1)) ImageSwiper_Industry.setCurrentPage(0,true);
                    else ImageSwiper_Industry.setCurrentPage(target+1,true);
                }
                imageSwiperAutoPlayEventHandler.sendEvent(0,2400, Priority.IDLE);
            }
            else if(event.eventId == 1)
            {
                imageSwiperAutoPlayEventHandler.removeAllEvent();
            }
        }
    }

    private ArrayList<ImageSwiper.DataItem> getSwiperImages_Industry() {
        ArrayList<ImageSwiper.DataItem> dataItems = new ArrayList<>();
        if(ResourceTool.getString(mContext,ResourceTable.String_language,"zh_CN").contains("en"))
        {
            dataItems.add(new ImageSwiper.DataItem(ResourceTable.Media_SpeedUpTheme_En));
            dataItems.add(new ImageSwiper.DataItem(ResourceTable.Media_ThemesBlindBoxIntelligence_En));
            dataItems.add(new ImageSwiper.DataItem(ResourceTable.Media_ColorfulIntelligence_En));
        }
        else
        {
            dataItems.add(new ImageSwiper.DataItem(ResourceTable.Media_SpeedUpTheme));
            dataItems.add(new ImageSwiper.DataItem(ResourceTable.Media_ThemesBlindBoxIntelligence));
            dataItems.add(new ImageSwiper.DataItem(ResourceTable.Media_ColorfulIntelligence));
        }
        return dataItems;
    }

    public void EndImageSwiper_Industry()
    {
        imageSwiperAutoPlayEventHandler.removeAllEvent();
        imageSwiperAutoPlayEventHandler.sendEvent(1,0,EventHandler.Priority.IMMEDIATE);
    }

    public void PauseImageSwiper_Industry(boolean EnableSmooth)
    {
        try
        {
            imageSwiperAutoPlayEventHandler.removeAllEvent();
            if(EnableSmooth)
            {
                if(mainSceneSlice.AllPages.getCurrentPage() == 1)
                    imageSwiperAutoPlayEventHandler.sendEvent(0,2400,EventHandler.Priority.IMMEDIATE);
                else imageSwiperAutoPlayEventHandler.sendEvent(1,0,EventHandler.Priority.IMMEDIATE);
            }else
            {
                imageSwiperAutoPlayEventHandler.sendEvent(1,0,EventHandler.Priority.IMMEDIATE);
            }
        }catch (Exception e){}
    }

    public void ReturnImageSwiper_Industry(boolean EnableSmooth)
    {
        try
        {
            mainSceneSlice.AllPages.setCurrentPage(mainSceneSlice.AllPages.getCurrentPage(),false);
            imageSwiperAutoPlayEventHandler.removeAllEvent();
            if(EnableSmooth)
            {
                if(mainSceneSlice.AllPages.getCurrentPage() == 1)
                    imageSwiperAutoPlayEventHandler.sendEvent(0,2400,EventHandler.Priority.IMMEDIATE);
                else imageSwiperAutoPlayEventHandler.sendEvent(1,0,EventHandler.Priority.IMMEDIATE);
            }else
            {
                imageSwiperAutoPlayEventHandler.sendEvent(1,0,EventHandler.Priority.IMMEDIATE);
            }
        }catch (Exception e){}
    }

    public void ContinueImageSwiper_Industry()
    {
        imageSwiperAutoPlayEventHandler.removeAllEvent();
        imageSwiperAutoPlayEventHandler.sendEvent(1,0,EventHandler.Priority.IMMEDIATE);
        imageSwiperAutoPlayEventHandler.removeAllEvent();
        imageSwiperAutoPlayEventHandler.sendEvent(0,2400,EventHandler.Priority.IDLE);
    }

    public void onClickNewScene(String SceneName,boolean isPlayingImageSwiper)
    {
        //防止自动轮播功能占用UI线程影响转场流畅度，无论当前是否在ImageSwiper页都应该停用，否则没到轮播间隔时间UI线程就会堵塞一次，即使没有执行自动滚动
        imageSwiperAutoPlayEventHandler.removeAllEvent();
        try
        {
            Class<AbilitySlice> c = (Class<AbilitySlice>) Class.forName("com.agger.harmonyosthemeseditor.abilities.slices."+SceneName+"Slice");
            AbilitySlice abilitySlice = c.newInstance();
            mainSceneSlice.present(abilitySlice,mainSceneSlice.getAbility().getIntent());
            ThemesEditorAbility.isMainSceneSlice = false;
            ThemesEditorAbility.LayoutChanged = false;
            DatabaseManager.Init(mainSceneSlice);
            DatabaseManager.setString("LastAbilityName",SceneName);
        }catch (Exception ex){}
        if(isPlayingImageSwiper)imageSwiperAutoPlayEventHandler.sendEvent(0,2400,EventHandler.Priority.IMMEDIATE);
        else imageSwiperAutoPlayEventHandler.sendEvent(1,0,EventHandler.Priority.IMMEDIATE); //重新激活自动轮播，防止轮播功能失效
    }

    public void onGetStatusInfo(boolean Advance)
    {
        //经测试，刘海屏或挖孔屏设备的用户，在显示设置下设置长期隐藏状态栏除了会给应用涂黑外，均不影响下列参数的获取
        Display display = DisplayManager.getInstance().getDefaultDisplay(mainSceneSlice).get();
        Point DisplayRealSize = new Point(0,0);
        display.getRealSize(DisplayRealSize);
        //（*须先在Ability的onStart方法下添加LayoutConfig.MARK_TRANSLUCENT_STATUS便签）
        //开始获取工作区的尺寸，如果是真全面屏设备，则普通模式下包含状态栏但不包含导航栏的尺寸，如果设备有挖孔或刘海，则返回去除状态栏高度后的尺寸
        //小窗口模式无论设备横竖屏，应用内界面均为竖屏展现，且获取的宽为屏幕实际宽度
        //但系统也会让应用视作正常竖屏状态下的屏幕密度和宽度来适配，仅回传的高度发生变化！
        //通常，设备在竖屏小窗口下环境获取的高度，要比横屏环境略高，1080P设备的高度值一般在1700-1800之间，与9:16比例略有差异~
        //分屏模式，获取的宽高为实际使用的屏幕区域尺寸，不会包含状态栏、导航栏、分割线与另一分屏中进程的尺寸
        //分屏模式下，系统不会让应用使用到状态栏区域，应用无需考虑界面被涂黑的问题
        int DisplayWidth = display.getAttributes().width;
        int DisplayHeight = display.getAttributes().height;
        //无论应用处于哪类场景，都会获取到整块屏幕的当前分辨率，设备分辨率降为720P，这里也会变成720P
        int DisplayRealSizeX = DisplayRealSize.getPointXToInt();
        int DisplayRealSizeY = DisplayRealSize.getPointYToInt();
        //0表示标准竖屏，1表示顶部传感器在左的横屏，2表示反向竖屏，3表示反向横屏,此参数在分屏或小窗口模式下准确性会丢失
        int DisplayRotation = display.getRotation();
        //获取当前设备的dpi参数，等价于DeviceCapabilityScreenDensity
        int DisplayDensityDpi = display.getAttributes().densityDpi;
        //DisplayDensityPixels等价于DisplayScalDensity，为Dpi除以160的值
        float DisplayDensityPixels = display.getAttributes().densityPixels;
        float DisplayScalDensity = display.getAttributes().scalDensity;
        //获取设备类型讯息
        DeviceCapability deviceCapability = mainSceneSlice.getResourceManager().getDeviceCapability();
        int deviceType = deviceCapability.deviceType;
        String DeviceType_Unknown = "Unknown";
        String DeviceType_PC = "PC";
        String DeviceType_Phone = "Phone";
        String DeviceType_Tablet = "Tablet";
        String DeviceType_Wearable = "Wearable";
        String DeviceType_TV = "Unknown";
        String DeviceType_Car = "Car";
        ResourceManager resManager = mainSceneSlice.getResourceManager();
        try
        {
            DeviceType_Unknown = resManager.getElement(ResourceTable.String_DeviceType_Unknown).getString();
            DeviceType_PC = resManager.getElement(ResourceTable.String_DeviceType_PC).getString();
            DeviceType_Phone = resManager.getElement(ResourceTable.String_DeviceType_Phone).getString();
            DeviceType_Tablet = resManager.getElement(ResourceTable.String_DeviceType_Tablet).getString();
            DeviceType_Wearable = resManager.getElement(ResourceTable.String_DeviceType_Wearable).getString();
            DeviceType_TV = resManager.getElement(ResourceTable.String_DeviceType_TV).getString();
            DeviceType_Car = resManager.getElement(ResourceTable.String_DeviceType_Car).getString();
        }catch (Exception e){}
        String DeviceTypeName = DeviceType_Unknown;
        if(deviceType == DeviceCapability.DEVICE_TYPE_PC)DeviceTypeName=DeviceType_PC;
        else if(deviceType == DeviceCapability.DEVICE_TYPE_PHONE)DeviceTypeName=DeviceType_Phone;
        else if(deviceType == DeviceCapability.DEVICE_TYPE_TABLET)DeviceTypeName=DeviceType_Tablet;
        else if(deviceType == DeviceCapability.DEVICE_TYPE_WEARABLE)DeviceTypeName=DeviceType_Wearable;
        else if(deviceType == DeviceCapability.DEVICE_TYPE_TV)DeviceTypeName=DeviceType_TV;
        else if(deviceType == DeviceCapability.DEVICE_TYPE_CAR)DeviceTypeName=DeviceType_Car;
        //获取设计用虚拟像素值，竖屏状态下此处宽度与开发者选项内最小宽度的dp一致
        //通常情况下，大部分手机系统显示设置-显示大小的选项“默认”为360dp、“大”为320dp、“小”为420dp左右
        //这里的虚拟像素乘以上面的DisplayDensityPixels或DisplayScalDensity，即为不包含状态栏和导航栏等的工作分辨率
        //这里的虚拟像素乘开后，无论设备是否有挖孔或刘海，均不包含状态栏高度，其它特性则均与DisplayWidth、DisplayHeight方法一致
        int DeviceCapabilityWidth = deviceCapability.width;
        int DeviceCapabilityHeight = deviceCapability.height;
        //获取当前设备的dpi参数，等价于DisplayDensityDpi
        int DeviceCapabilityScreenDensity = deviceCapability.screenDensity;

        String AllInfo_DeviceType = "设备类型：";
        String AllInfo_ScreenDensity = "屏幕密度：";
        String AllInfo_DisplayResolution = "当前分辨率：";
        try
        {
            AllInfo_DeviceType = resManager.getElement(ResourceTable.String_AllInfo_DeviceType).getString();
            AllInfo_ScreenDensity = resManager.getElement(ResourceTable.String_AllInfo_ScreenDensity).getString();
            AllInfo_DisplayResolution = resManager.getElement(ResourceTable.String_AllInfo_DisplayResolution).getString();
        }catch (Exception e){}
        if(Advance) new GeneralToast(mContext).setText("DisplayRotation："+DisplayRotation+"\r\nDisplayWidth："+DisplayWidth+"\r\nDisplayHeight："+DisplayHeight+"\r\nDisplayRealSizeX："+DisplayRealSizeX+"\r\nDisplayRealSizeY："+DisplayRealSizeY+"\r\nDeviceCapabilityWidth："+DeviceCapabilityWidth+"\r\nDeviceCapabilityHeight："+DeviceCapabilityHeight+"\r\nDisplayDensityDpi："+DisplayDensityDpi+"\r\nDeviceCapabilityScreenDensity："+DeviceCapabilityScreenDensity+"\r\nDisplayDensityPixels："+DisplayDensityPixels+"\r\nDisplayScalDensity："+DisplayScalDensity).show();
        else new GeneralToast(mContext).setText(AllInfo_DeviceType+DeviceTypeName+"\r\n"+AllInfo_ScreenDensity+DeviceCapabilityScreenDensity+"dpi"+"\r\n"+AllInfo_DisplayResolution+DisplayRealSizeX+'×'+DisplayRealSizeY).show();
    }

    public void onClickCheckUpdate()
    {
        //API4之前仅涉及智慧屏、手表等设备，不包含平板和手机，API4是首个支持手机和平板的鸿蒙2.0，API5为鸿蒙2.1，API6为鸿蒙2.2，API7为鸿蒙3.0
        //事实上，大部分鸿蒙2.0的手机或平板，早已换作API5鸿蒙2.1的内核，仅仅只是UI还停留在2.0，因此华为分析后台会将这些API5的设备识别为鸿蒙2.1，而系统关于界面却仍然是鸿蒙2.0
        int API_Version_Code = 0;
        try
        {
            SystemVersion _SystemVersion = new SystemVersion();
            API_Version_Code = _SystemVersion.getApiVersion();
        }catch (Exception ex){}
        if(API_Version_Code >= 6)
        {
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withAction("ability.intent.VIEW_DATA")
                    .withUri(Uri.parse("appmarket://details?id=com.agger.harmonyosthemeseditor"))
                    .build();
            intent.setOperation(operation);
            mainSceneSlice.startAbility(intent);
        }else
        {
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withAction("android.intent.action.VIEW")
                    .withUri(Uri.parse("appmarket://details?id=com.agger.harmonyosthemeseditor"))
                    .withFlags(Intent.FLAG_NOT_OHOS_COMPONENT)
                    .build();
            intent.setOperation(operation);
            mainSceneSlice.startAbility(intent);
        }
    }

    public void UpdateRemoteJson()
    {
        try
        {
            String dataStr = ResourceTool.getString(mainSceneSlice,ResourceTable.String_language,"zh_CN");
            String ConfigType = "Local";
            String SmartCard_Title = "智慧贴士",
                    SmartCard_Content = "1. 相片异构能力，升华你的精彩瞬间！\r\n2. 智慧色彩能力，让生活的色彩更有趣~",
                    SmartCard_Date = "2021.10.23";
            if(!ThemesEditorAbility.QuitBySelf_Last)
            {
                ThemesEditorAbility.Instance.config = AGConnectConfig.getInstance();
                ThemesEditorAbility.Instance.config.applyDefault(ResourceTable.Profile_configdefault);
                int i = 0;
                while((i<3)||((ConfigType.equals("Local"))&&(i<8)))
                {
                    ConfigValues last = ThemesEditorAbility.Instance.config.loadLastFetched();
                    ThemesEditorAbility.Instance.config.apply(last);
                    ThemesEditorAbility.Instance.config.fetch(3600)
                            .addOnSuccessListener(configValues -> {})
                            .addOnFailureListener(e -> {});
                    ConfigType = ThemesEditorAbility.Instance.config.getValueAsString("ConfigType");
                    SmartCard_Date = ThemesEditorAbility.Instance.config.getValueAsString("SmartCard_Date");
                    String SmartCard_Title_JSON = ThemesEditorAbility.Instance.config.getValueAsString("SmartCard_Title");
                    String SmartCard_Content_JSON = ThemesEditorAbility.Instance.config.getValueAsString("SmartCard_Content");

                    RequestParam_i18n SmartCard_Title_Param= new RequestParam_i18n();
                    try {SmartCard_Title_Param = ZSONObject.stringToClass(SmartCard_Title_JSON, RequestParam_i18n.class);}
                    catch (RuntimeException e) {}
                    if(dataStr.equals("zh_CN"))
                        SmartCard_Title = SmartCard_Title_Param.zh_CN;
                    else if(dataStr.equals("bo_CN"))
                        SmartCard_Title = SmartCard_Title_Param.bo_CN;
                    else if(dataStr.equals("ug_CN"))
                        SmartCard_Title = SmartCard_Title_Param.ug_CN;
                    else if(dataStr.equals("zh_HK"))
                        SmartCard_Title = SmartCard_Title_Param.zh_HK;
                    else if(dataStr.equals("zh_TW"))
                        SmartCard_Title = SmartCard_Title_Param.zh_TW;
                    else if(dataStr.equals("ja_JP"))
                        SmartCard_Title = SmartCard_Title_Param.ja_JP;
                    else if(dataStr.equals("ko_KR"))
                        SmartCard_Title = SmartCard_Title_Param.ko_KR;
                    else if(dataStr.equals("en_US"))
                        SmartCard_Title = SmartCard_Title_Param.en_US;
                    else if(dataStr.equals("en_GB"))
                        SmartCard_Title = SmartCard_Title_Param.en_GB;
                    else if(dataStr.equals("fr_FR"))
                        SmartCard_Title = SmartCard_Title_Param.fr_FR;
                    else if(dataStr.equals("de_DE"))
                        SmartCard_Title = SmartCard_Title_Param.de_DE;
                    else if(dataStr.equals("ru_RU"))
                        SmartCard_Title = SmartCard_Title_Param.ru_RU;
                    else if(dataStr.equals("es_LA"))
                        SmartCard_Title = SmartCard_Title_Param.es_LA;
                    else if(dataStr.equals("es_ES"))
                        SmartCard_Title = SmartCard_Title_Param.es_ES;
                    else if(dataStr.equals("ar_AE"))
                        SmartCard_Title = SmartCard_Title_Param.ar_AE;
                    else if(dataStr.equals("pt_PT"))
                        SmartCard_Title = SmartCard_Title_Param.pt_PT;
                    else if(dataStr.equals("pt_BR"))
                        SmartCard_Title = SmartCard_Title_Param.pt_BR;
                    else if(dataStr.equals("it_IT"))
                        SmartCard_Title = SmartCard_Title_Param.it_IT;

                    RequestParam_i18n SmartCard_Content_Param= new RequestParam_i18n();
                    try {SmartCard_Content_Param = ZSONObject.stringToClass(SmartCard_Content_JSON, RequestParam_i18n.class);}
                    catch (RuntimeException e) {}
                    if(dataStr.equals("zh_CN"))
                        SmartCard_Content = SmartCard_Content_Param.zh_CN;
                    else if(dataStr.equals("bo_CN"))
                        SmartCard_Content = SmartCard_Content_Param.bo_CN;
                    else if(dataStr.equals("ug_CN"))
                        SmartCard_Content = SmartCard_Content_Param.ug_CN;
                    else if(dataStr.equals("zh_HK"))
                        SmartCard_Content = SmartCard_Content_Param.zh_HK;
                    else if(dataStr.equals("zh_TW"))
                        SmartCard_Content = SmartCard_Content_Param.zh_TW;
                    else if(dataStr.equals("ja_JP"))
                        SmartCard_Content = SmartCard_Content_Param.ja_JP;
                    else if(dataStr.equals("ko_KR"))
                        SmartCard_Content = SmartCard_Content_Param.ko_KR;
                    else if(dataStr.equals("en_US"))
                        SmartCard_Content = SmartCard_Content_Param.en_US;
                    else if(dataStr.equals("en_GB"))
                        SmartCard_Content = SmartCard_Content_Param.en_GB;
                    else if(dataStr.equals("fr_FR"))
                        SmartCard_Content = SmartCard_Content_Param.fr_FR;
                    else if(dataStr.equals("de_DE"))
                        SmartCard_Content = SmartCard_Content_Param.de_DE;
                    else if(dataStr.equals("ru_RU"))
                        SmartCard_Content = SmartCard_Content_Param.ru_RU;
                    else if(dataStr.equals("es_LA"))
                        SmartCard_Content = SmartCard_Content_Param.es_LA;
                    else if(dataStr.equals("es_ES"))
                        SmartCard_Content = SmartCard_Content_Param.es_ES;
                    else if(dataStr.equals("ar_AE"))
                        SmartCard_Content = SmartCard_Content_Param.ar_AE;
                    else if(dataStr.equals("pt_PT"))
                        SmartCard_Content = SmartCard_Content_Param.pt_PT;
                    else if(dataStr.equals("pt_BR"))
                        SmartCard_Content = SmartCard_Content_Param.pt_BR;
                    else if(dataStr.equals("it_IT"))
                        SmartCard_Content = SmartCard_Content_Param.it_IT;
                    i++;
                }
            }
            else
            {
                SmartCard_Date = ThemesEditorAbility.Instance.config.getValueAsString("SmartCard_Date");
                String SmartCard_Title_JSON = ThemesEditorAbility.Instance.config.getValueAsString("SmartCard_Title");
                String SmartCard_Content_JSON = ThemesEditorAbility.Instance.config.getValueAsString("SmartCard_Content");

                RequestParam_i18n SmartCard_Title_Param= new RequestParam_i18n();
                try {SmartCard_Title_Param = ZSONObject.stringToClass(SmartCard_Title_JSON, RequestParam_i18n.class);}
                catch (RuntimeException e) {}
                if(dataStr.equals("zh_CN"))
                    SmartCard_Title = SmartCard_Title_Param.zh_CN;
                else if(dataStr.equals("bo_CN"))
                    SmartCard_Title = SmartCard_Title_Param.bo_CN;
                else if(dataStr.equals("ug_CN"))
                    SmartCard_Title = SmartCard_Title_Param.ug_CN;
                else if(dataStr.equals("zh_HK"))
                    SmartCard_Title = SmartCard_Title_Param.zh_HK;
                else if(dataStr.equals("zh_TW"))
                    SmartCard_Title = SmartCard_Title_Param.zh_TW;
                else if(dataStr.equals("ja_JP"))
                    SmartCard_Title = SmartCard_Title_Param.ja_JP;
                else if(dataStr.equals("ko_KR"))
                    SmartCard_Title = SmartCard_Title_Param.ko_KR;
                else if(dataStr.equals("en_US"))
                    SmartCard_Title = SmartCard_Title_Param.en_US;
                else if(dataStr.equals("en_GB"))
                    SmartCard_Title = SmartCard_Title_Param.en_GB;
                else if(dataStr.equals("fr_FR"))
                    SmartCard_Title = SmartCard_Title_Param.fr_FR;
                else if(dataStr.equals("de_DE"))
                    SmartCard_Title = SmartCard_Title_Param.de_DE;
                else if(dataStr.equals("ru_RU"))
                    SmartCard_Title = SmartCard_Title_Param.ru_RU;
                else if(dataStr.equals("es_LA"))
                    SmartCard_Title = SmartCard_Title_Param.es_LA;
                else if(dataStr.equals("es_ES"))
                    SmartCard_Title = SmartCard_Title_Param.es_ES;
                else if(dataStr.equals("ar_AE"))
                    SmartCard_Title = SmartCard_Title_Param.ar_AE;
                else if(dataStr.equals("pt_PT"))
                    SmartCard_Title = SmartCard_Title_Param.pt_PT;
                else if(dataStr.equals("pt_BR"))
                    SmartCard_Title = SmartCard_Title_Param.pt_BR;
                else if(dataStr.equals("it_IT"))
                    SmartCard_Title = SmartCard_Title_Param.it_IT;

                RequestParam_i18n SmartCard_Content_Param= new RequestParam_i18n();
                try {SmartCard_Content_Param = ZSONObject.stringToClass(SmartCard_Content_JSON, RequestParam_i18n.class);}
                catch (RuntimeException e) {}
                if(dataStr.equals("zh_CN"))
                    SmartCard_Content = SmartCard_Content_Param.zh_CN;
                else if(dataStr.equals("bo_CN"))
                    SmartCard_Content = SmartCard_Content_Param.bo_CN;
                else if(dataStr.equals("ug_CN"))
                    SmartCard_Content = SmartCard_Content_Param.ug_CN;
                else if(dataStr.equals("zh_HK"))
                    SmartCard_Content = SmartCard_Content_Param.zh_HK;
                else if(dataStr.equals("zh_TW"))
                    SmartCard_Content = SmartCard_Content_Param.zh_TW;
                else if(dataStr.equals("ja_JP"))
                    SmartCard_Content = SmartCard_Content_Param.ja_JP;
                else if(dataStr.equals("ko_KR"))
                    SmartCard_Content = SmartCard_Content_Param.ko_KR;
                else if(dataStr.equals("en_US"))
                    SmartCard_Content = SmartCard_Content_Param.en_US;
                else if(dataStr.equals("en_GB"))
                    SmartCard_Content = SmartCard_Content_Param.en_GB;
                else if(dataStr.equals("fr_FR"))
                    SmartCard_Content = SmartCard_Content_Param.fr_FR;
                else if(dataStr.equals("de_DE"))
                    SmartCard_Content = SmartCard_Content_Param.de_DE;
                else if(dataStr.equals("ru_RU"))
                    SmartCard_Content = SmartCard_Content_Param.ru_RU;
                else if(dataStr.equals("es_LA"))
                    SmartCard_Content = SmartCard_Content_Param.es_LA;
                else if(dataStr.equals("es_ES"))
                    SmartCard_Content = SmartCard_Content_Param.es_ES;
                else if(dataStr.equals("ar_AE"))
                    SmartCard_Content = SmartCard_Content_Param.ar_AE;
                else if(dataStr.equals("pt_PT"))
                    SmartCard_Content = SmartCard_Content_Param.pt_PT;
                else if(dataStr.equals("pt_BR"))
                    SmartCard_Content = SmartCard_Content_Param.pt_BR;
                else if(dataStr.equals("it_IT"))
                    SmartCard_Content = SmartCard_Content_Param.it_IT;
            }
            SmartCard_Date = ThemesEditorAbility.Instance.config.getValueAsString("SmartCard_Date");

            iBoard_Title.setText(SmartCard_Title);
            iBoard_Content.setText(SmartCard_Content);
            iBoard_Date.setText(SmartCard_Date);
        }catch (Exception ex){}
    }

    //数据实体类
    public static class DataItem
    {
        int mResId;
        public DataItem(int resId) {
            mResId = resId;
        }
    }
    // 数据源，每个页面对应list中的一项
    private List<DataItem> list;
    private Context mContext;

    public PageSwiper(List<DataItem> list, Context context)
    {
        this.list = list;
        this.mContext = context;
        this.objects = new Object[list.size()];
    }
    @Override
    public int getCount() {
        return list.size();
    }
    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        //PageSlider执行setCurrentPage时，会对每个page执行销毁再重绘，但是当前PageSlider内部page过于复杂，销毁重绘会严重影响setCurrentPage速度
        //因此我们手动禁止它销毁和重绘，然后在执行setCurrentPage时，模拟Sliding方式切换页面，即修改PageSlider下级的DirectionalLayout组件的坐标
        //修改完PageSlider下级的DirectionalLayout组件的坐标后，虽然已完成页面切换，但是很快会弹回原来的位置，这是因为PageSlider内部记忆的当前page值并没有变更，所以我们还是要继续执行setCurrentPage的
        //PageSlider为横向时，下级的DirectionalLayout组件高度与其包含的每个ComponentContainer一致，宽度为所有包含的ComponentContainer之和，也就是parent组件PageSlider的宽度乘以下级组件数量
        if(!Complete)
        {
            final DataItem data = list.get(i);
            DirectionalLayout pageLayout = (DirectionalLayout) LayoutScatter.getInstance(mContext)
                    .parse(data.mResId, null, false);
            if(data.mResId==ResourceTable.Layout_page_industry)
            {
                float functionbox_alpha = (ResourceTool.getColor(mContext, ResourceTable.Color_dawnlighti_color_mode,-1)==-16777216)?0.72f:1f;
                ImageSwiper_Industry = (PageSlider)pageLayout.findComponentById(ResourceTable.Id_ImageSwiper_Industry);
                PageSliderIndicator ImageSwiperIndicator_Industry = (PageSliderIndicator)pageLayout.findComponentById(ResourceTable.Id_ImageSwiperIndicator_Industry);
                ImageSwiper_Industry.setProvider(new ImageSwiper(getSwiperImages_Industry(), mContext));
                ImageSwiper_Industry.setSlidingPossible(true);
                ImageSwiper_Industry.setReboundEffect(false);
                int API_Version_Code = 6;
                try
                {
                    SystemVersion _SystemVersion = new SystemVersion();
                    API_Version_Code = _SystemVersion.getApiVersion();
                }catch (Exception ex){}
                if(API_Version_Code>=5)
                    ImageSwiper_Industry.setCircularModeEnabled(true);
                ImageSwiperIndicator_Industry.setPageSlider(ImageSwiper_Industry);
                ImageSwiperAutoPlayEventRunner = EventRunner.current();
                ProcessManager.setThreadPriority(-20);
                imageSwiperAutoPlayEventHandler = new ImageSwiperAutoPlayEventHandler(ImageSwiperAutoPlayEventRunner);
                imageSwiperAutoPlayEventHandler.sendEvent(0,0, EventHandler.Priority.IMMEDIATE);
                ImageSwiper_Industry.addPageChangedListener(new PageSlider.PageChangedListener()
                {
                    @Override
                    public void onPageSliding(int itemPos, float itemPosOffset, int itemPosPixles)
                    {
                        imageSwiperAutoPlayEventHandler.removeAllEvent();
                        imageSwiperAutoPlayEventHandler.sendEvent(0,1200,EventHandler.Priority.IDLE);
                    }
                    @Override
                    public void onPageSlideStateChanged(int state) {}
                    @Override
                    public void onPageChosen(int itemPos) {}
                });
                Component Image_VideoUnlock = pageLayout.findComponentById(ResourceTable.Id_Image_VideoUnlock);
                Component Image_SpeedUpTheme = pageLayout.findComponentById(ResourceTable.Id_Image_SpeedUpTheme);
                Component Image_IconIntelligence = pageLayout.findComponentById(ResourceTable.Id_Image_IconIntelligence);
                Component Image_ThemesBlindBox = pageLayout.findComponentById(ResourceTable.Id_Image_ThemesBlindBox);
                Component Image_ImageEnhancement = pageLayout.findComponentById(ResourceTable.Id_Image_ImageEnhancement);
                Component Image_PhotoCropPlus = pageLayout.findComponentById(ResourceTable.Id_Image_PhotoCropPlus);
                Image Image_ColorSpaceIntelligence = (Image)pageLayout.findComponentById(ResourceTable.Id_Image_ColorSpaceIntelligence);
                Component Image_StatusInfo = pageLayout.findComponentById(ResourceTable.Id_Image_StatusInfo);
                //防止应用偶尔不加载该元素造成显示不佳
                Image_ColorSpaceIntelligence.setImageElement(new VectorElement(mContext,ResourceTable.Graphic_ic_colorspace_intelligence));
                Image_VideoUnlock.setAlpha(functionbox_alpha);
                Image_SpeedUpTheme.setAlpha(functionbox_alpha);
                Image_IconIntelligence.setAlpha(functionbox_alpha);
                Image_ThemesBlindBox.setAlpha(functionbox_alpha);
                Image_ImageEnhancement.setAlpha(functionbox_alpha);
                Image_PhotoCropPlus.setAlpha(functionbox_alpha);
                //Image_ColorSpaceIntelligence.setAlpha(functionbox_alpha);
                Image_StatusInfo.setAlpha(functionbox_alpha);
                Image_VideoUnlock.setClickedListener(c-> onClickNewScene(SystemVersion.getApiVersion()>=6?"UnlockPlus_Fluid":"UnlockPlus",true));
                Image_SpeedUpTheme.setClickedListener(c-> onClickNewScene(SystemVersion.getApiVersion()>=6?"SpeedUpTheme_Fluid":"SpeedUpTheme",true));
                Image_IconIntelligence.setClickedListener(c-> onClickNewScene("SmartIcon",true));
                Image_ThemesBlindBox.setClickedListener(c-> onClickNewScene("ThemesBlindBox",true));
                Image_ImageEnhancement.setClickedListener(c-> onClickNewScene("ImageEnhancement",true));
                Image_PhotoCropPlus.setClickedListener(c-> onClickNewScene("PhotoCropPlus",true));
                Image_ColorSpaceIntelligence.setClickedListener(c-> onClickNewScene("ColorSpaceIntelligence",true));
                Image_StatusInfo.setClickedListener(c-> onGetStatusInfo(false));
                Image_StatusInfo.setLongClickedListener(c-> onGetStatusInfo(true));
                pageLayout.findComponentById(ResourceTable.Id_page_content).setScrolledListener((component, i12, i1, i2, i3) -> PauseImageSwiper_Industry(true));
                DeviceCapability deviceCapability = mainSceneSlice.getResourceManager().getDeviceCapability();
                if(deviceCapability.width < 360)
                {
                    DisplayAttributes displayAttributes = DisplayManager.getInstance().getDefaultDisplay(mContext).get().getAttributes();
                    int maxHeight = (int)((0.5f*deviceCapability.width+3f)*displayAttributes.scalDensity+0.5f);
                    ImageSwiper_Industry.setHeight(maxHeight);
                }
            }else if(data.mResId==ResourceTable.Layout_page_more)
            {
                iBoard_Base = pageLayout.findComponentById(ResourceTable.Id_iBoard_Base);
                iBoard_Content_Layout = pageLayout.findComponentById(ResourceTable.Id_iBoard_Content_Layout);
                iBoard_Date_Layout = pageLayout.findComponentById(ResourceTable.Id_iBoard_Date_Layout);
                DeviceCapability deviceCapability = mainSceneSlice.getResourceManager().getDeviceCapability();
                if(deviceCapability.width > 360)
                {
                    DisplayAttributes displayAttributes = DisplayManager.getInstance().getDefaultDisplay(mContext).get().getAttributes();
                    int maxWidth = (int)(320f*displayAttributes.scalDensity+0.5f);
                    iBoard_Base.setWidth(maxWidth);
                    iBoard_Content_Layout.setWidth(maxWidth);
                    iBoard_Date_Layout.setWidth(maxWidth);
                }
                iBoard_Title = (Text) pageLayout.findComponentById(ResourceTable.Id_iBoard_Title);
                iBoard_Content = (Text) pageLayout.findComponentById(ResourceTable.Id_iBoard_Content);
                iBoard_Date = (Text) pageLayout.findComponentById(ResourceTable.Id_iBoard_Date);
                UpdateRemoteJson();
                Component SettingsCard_Details = pageLayout.findComponentById(ResourceTable.Id_SettingsCard_Area_Details);
                Component SettingsCard_Update = pageLayout.findComponentById(ResourceTable.Id_SettingsCard_Area_Update);
                Component SettingsCard_About = pageLayout.findComponentById(ResourceTable.Id_SettingsCard_Area_About);
                SettingsCard_Details.setComponentStateChangedListener((component, i13) ->
                {
                    if(i13 == 18432)
                        pageLayout.findComponentById(ResourceTable.Id_SettingsCard_Pressed_Details).setVisibility(Component.VISIBLE);
                    else
                        pageLayout.findComponentById(ResourceTable.Id_SettingsCard_Pressed_Details).setVisibility(Component.INVISIBLE);
                });
                SettingsCard_Update.setComponentStateChangedListener((component, i14) ->
                {
                    if(i14 == 18432)
                        pageLayout.findComponentById(ResourceTable.Id_SettingsCard_Pressed_Update).setVisibility(Component.VISIBLE);
                    else
                        pageLayout.findComponentById(ResourceTable.Id_SettingsCard_Pressed_Update).setVisibility(Component.INVISIBLE);
                });
                SettingsCard_About.setComponentStateChangedListener((component, i15) ->
                {
                    if(i15 == 18432)
                        pageLayout.findComponentById(ResourceTable.Id_SettingsCard_Pressed_About).setVisibility(Component.VISIBLE);
                    else
                        pageLayout.findComponentById(ResourceTable.Id_SettingsCard_Pressed_About).setVisibility(Component.INVISIBLE);
                });
                SettingsCard_Details.setClickedListener(c-> onClickNewScene("Settings",false));
                SettingsCard_Update.setClickedListener(c-> onClickCheckUpdate());
                SettingsCard_About.setClickedListener(c-> onClickNewScene("About",false));
            }
            componentContainer.addComponent(pageLayout);
            objects[i] = pageLayout;
            if(i == (list.size()-1))Complete = true;
            return pageLayout;
        }
        else return objects[i];
    }
    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o)
    {
        //PageSlider执行setCurrentPage时，会对每个page执行销毁再重绘，但是当前PageSlider内部page过于复杂，销毁重绘会严重影响setCurrentPage速度
        //因此我们手动禁止它销毁和重绘，然后在执行setCurrentPage时，模拟Sliding方式切换页面，即修改PageSlider下级的DirectionalLayout组件的坐标
        //修改完PageSlider下级的DirectionalLayout组件的坐标后，虽然已完成页面切换，但是很快会弹回原来的位置，这是因为PageSlider内部记忆的当前page值并没有变更，所以我们还是要继续执行setCurrentPage的
        //PageSlider为横向时，下级的DirectionalLayout组件高度与其包含的每个ComponentContainer一致，宽度为所有包含的ComponentContainer之和，也就是parent组件PageSlider的宽度乘以下级组件数量
        //移除原来的componentContainer.removeComponent((Component) o);方法
    }
    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        //可添加具体处理逻辑
        return true;
    }
}
